initrd and initramfs

In [2]:
ls /boot
abi-4.4.0-77-generic         initrd.img-4.4.0-78-generic
abi-4.4.0-78-generic         lost+found
config-4.4.0-77-generic      System.map-4.4.0-77-generic
config-4.4.0-78-generic      System.map-4.4.0-78-generic
grub                         vmlinuz-4.4.0-77-generic
initrd.img-4.4.0-77-generic  vmlinuz-4.4.0-78-generic

initrd and initramfs

  • Generic Linux kernel image: to boot on a wide variety of hardware
  • Device drivers: loadable kernel modules [N12]
    • statically compiling many drivers into one kernel causes the kernel image to be much larger, perhaps too large to boot on computers with limited memory.

raises the problem of detecting and loading the modules necessary to mount the root file system at boot time

  • The root file system may be on a software RAID volume, LVM, NFS
  • Encrypted partition
  • Hibernation: swap partition, making image available

To avoid having to hardcode handling for so many special cases into the kernel, an initial boot stage with a temporary root file-system is used.

  • contains user-space helpers which do:
    • The hardware detection
    • Module loading
    • Device discovery necessary

To get the real root file-system mounted.

  • initrd
    • A ramdev block device is created (uses memory instead of physical disks to simulated hard disk that)
    • The initrd file is read and unzipped into the device
    • Mount the filesystem as usual: . Naturally, filesystems need a driver, so if you use ext2, the ext2 driver has to be compiled in-kernel.
In [ ]:
zcat initrd | dd of=/dev/ram0
In [ ]:
mount /dev/ram0 /root
  • initramfs
    • The archive is unpacked by the kernel into a special instance of a tmpfs that becomes the initial root file system
      • A tmpfs is mounted
        • Doesn't need a driver, it is always on-kernel, No device needed, No additional drivers.
        • Advantage of not requiring an intermediate file system or block drivers to be compiled into the kernel
      • The initramfs is uncompressed directly into this new filesystem
In [ ]:
mount -t tmpfs nodev /root
In [ ]:
zcat initramfs | cpio -i

Lecture notes


License

Creative Commons License

Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


ravexina's gitlab

ravexina's github